﻿using System.Collections.Generic;
using Lightray.Hattrick.ChppLib.EntityTypes;

namespace Lightray.Hattrick.ChppLib
{
    public class Utility
    {
        private static Dictionary<string, Country> ISO3166_TO_COUNTRY_MAP = new Dictionary<string, Country>()
        {
            { "SE", Country.Sweden },
            { "DE", Country.Germany },
            { "IT", Country.Italy },
            { "FR", Country.France },
            { "MX", Country.Mexico },
            { "AR", Country.Argentina },
            { "NO", Country.Norway },
            { "DK", Country.Denmark },
            { "FI", Country.Finland },
            { "NL", Country.Netherlands },
            { "CA", Country.Canada },
            { "IE", Country.Ireland },
            { "CL", Country.Chile },
            { "CO", Country.Colombia },
            { "UY", Country.Uruguay },
            { "PE", Country.Peru },
            { "BR", Country.Brazil },
            { "PT", Country.Portugal },
            { "JP", Country.Japan },
            { "PL", Country.Poland },
            { "IN", Country.India },
            { "CN", Country.China },
            { "TH", Country.Thailand },
            { "TR", Country.Turkey },
            { "EG", Country.Egypt },
            { "AT", Country.Austria },
            { "ES", Country.Spain },
            { "RO", Country.Romania },
            { "IS", Country.Iceland },
            { "BE", Country.Belgium },
            { "MY", Country.Malaysia },
            { "CH", Country.Switzerland },
            { "SG", Country.Singapore },
            { "HR", Country.Croatia },
            { "RS", Country.Serbia },
            { "HU", Country.Hungary },
            { "GR", Country.Greece },
            { "EE", Country.Estonia },
            { "LV", Country.Latvia },
            { "ID", Country.Indonesia },
            { "PH", Country.Philippines },
            { "IL", Country.Israel },
            { "BG", Country.Bulgaria },
            { "SI", Country.Slovenia },
            { "LT", Country.Lithuania },
            { "UA", Country.Ukraine },
            { "PK", Country.Pakistan },
            { "SK", Country.Slovakia },
            { "PY", Country.Paraguay },
            { "EC", Country.Ecuador },
            { "NG", Country.Nigeria },
            { "MA", Country.Morocco },
            { "TN", Country.Tunisia },
            { "LU", Country.Luxembourg },
            { "CY", Country.Cyprus },
            { "SN", Country.Senegal },
            { "BY", Country.Belarus },
            { "JM", Country.Jamaica },
            { "KE", Country.Kenya },
            { "PA", Country.Panama },
            { "CU", Country.Cuba },
            { "AL", Country.Albania },
            { "HN", Country.Honduras },
            { "MT", Country.Malta },
            { "KG", Country.Kyrgyzstan },
            { "GE", Country.Georgia },
            { "AD", Country.Andorra },
            { "GT", Country.Guatemala },
            { "JO", Country.Jordan },
            { "AM", Country.Armenia },
            { "NI", Country.Nicaragua },
            { "KZ", Country.Kazakhstan },
            { "SR", Country.Suriname },
            { "LI", Country.Liechtenstein },
            { "DZ", Country.Algeria },
            { "MN", Country.Mongolia },
            { "LB", Country.Lebanon },
            { "BH", Country.Bahrain },
            { "BB", Country.Barbados },
            { "AZ", Country.Azerbaijan },
            { "KW", Country.Kuwait },
            { "IQ", Country.Iraq },
            { "ME", Country.Montenegro },
            { "AO", Country.Angola },
            { "BD", Country.Bangladesh },
            { "YE", Country.Yemen },
            { "OM", Country.Oman },
            { "MZ", Country.Mozambique },
            { "GH", Country.Ghana },
            { "KH", Country.Cambodia },
            { "BJ", Country.Benin },
            { "QA", Country.Qatar },
            { "UG", Country.Uganda },
            { "MV", Country.Maldives },
            { "UZ", Country.Uzbekistan },
            { "CM", Country.Cameroon },
            { "ENGLAND", Country.England },
            { "US", Country.USA },
            { "AU", Country.Oceania },
            { "SCOTLAND", Country.Scotland },
            { "VE", Country.Venezuela },
            { "ZA", Country.SouthAfrica },
            { "KR", Country.SouthKorea },
            { "RU", Country.Russia },
            { "CZ", Country.CzechRepublic },
            { "TW", Country.ChineseTaipei },
            { "HK", Country.HongKong },
            { "WALES", Country.Wales },
            { "BA", Country.BosniaHerzegovina },
            { "VN", Country.Vietnam },
            { "BO", Country.Bolivia },
            { "FO", Country.FaroeIslands },
            { "SA", Country.SaudiArabia },
            { "CR", Country.CostaRica },
            { "AE", Country.UnitedArabEmirates },
            { "IR", Country.Iran },
            { "DO", Country.DominicanRepublic },
            { "GB", Country.NorthernIreland },
            { "MK", Country.FYRMacedonia },
            { "SV", Country.ElSalvador },
            { "MD", Country.Moldova },
            { "TT", Country.TrinidadTobago },
            { "CV", Country.CapeVerde },
            { "CI", Country.IvoryCoast },
            { "BN", Country.Brunei },
            { "SY", Country.Syria },
            { "TZ", Country.Tanzania },
            { "PS", Country.Palestine },
        };
        
        // updated when a new flag is added for a country
        public static string CountryAsIso3166(Country country)
        {
            switch (country)
            {
                case Country.Sweden:
                    return "SE";
                case Country.Germany:
                    return "DE";
                case Country.Italy:
                    return "IT";
                case Country.France:
                    return "FR";
                case Country.Mexico:
                    return "MX";
                case Country.Argentina:
                    return "AR";
                case Country.Norway:
                    return "NO";
                case Country.Denmark:
                    return "DK";
                case Country.Finland:
                    return "FI";
                case Country.Netherlands:
                    return "NL";
                case Country.Canada:
                    return "CA";
                case Country.Ireland:
                    return "IE";
                case Country.Chile:
                    return "CL";
                case Country.Colombia:
                    return "CO";
                case Country.Uruguay:
                    return "UY";
                case Country.Peru:
                    return "PE";
                case Country.Brazil:
                    return "BR";
                case Country.Portugal:
                    return "PT";
                case Country.Japan:
                    return "JP";
                case Country.Poland:
                    return "PL";
                case Country.India:
                    return "IN";
                case Country.China:
                    return "CN";
                case Country.Thailand:
                    return "TH";
                case Country.Turkey:
                    return "TR";
                case Country.Egypt:
                    return "EG";
                case Country.Austria:
                    return "AT";
                case Country.Spain:
                    return "ES";
                case Country.Romania:
                    return "RO";
                case Country.Iceland:
                    return "IS";
                case Country.Belgium:
                    return "BE";
                case Country.Malaysia:
                    return "MY";
                case Country.Switzerland:
                    return "CH";
                case Country.Singapore:
                    return "SG";
                case Country.Croatia:
                    return "HR";
                case Country.Serbia:
                    return "RS";
                case Country.Hungary:
                    return "HU";
                case Country.Greece:
                    return "GR";
                case Country.Estonia:
                    return "EE";
                case Country.Latvia:
                    return "LV";
                case Country.Indonesia:
                    return "ID";
                case Country.Philippines:
                    return "PH";
                case Country.Israel:
                    return "IL";
                case Country.Bulgaria:
                    return "BG";
                case Country.Slovenia:
                    return "SI";
                case Country.Lithuania:
                    return "LT";
                case Country.Ukraine:
                    return "UA";
                case Country.Pakistan:
                    return "PK";
                case Country.Slovakia:
                    return "SK";
                case Country.Paraguay:
                    return "PY";
                case Country.Ecuador:
                    return "EC";
                case Country.Nigeria:
                    return "NG";
                case Country.Morocco:
                    return "MA";
                case Country.Tunisia:
                    return "TN";
                case Country.Luxembourg:
                    return "LU";
                case Country.Cyprus:
                    return "CY";
                case Country.Senegal:
                    return "SN";
                case Country.Belarus:
                    return "BY";
                case Country.Jamaica:
                    return "JM";
                case Country.Kenya:
                    return "KE";
                case Country.Panama:
                    return "PA";
                case Country.Cuba:
                    return "CU";
                case Country.Albania:
                    return "AL";
                case Country.Honduras:
                    return "HN";
                case Country.Malta:
                    return "MT";
                case Country.Kyrgyzstan:
                    return "KG";
                case Country.Georgia:
                    return "GE";
                case Country.Andorra:
                    return "AD";
                case Country.Guatemala:
                    return "GT";
                case Country.Jordan:
                    return "JO";
                case Country.Armenia:
                    return "AM";
                case Country.Nicaragua:
                    return "NI";
                case Country.Kazakhstan:
                    return "KZ";
                case Country.Suriname:
                    return "SR";
                case Country.Liechtenstein:
                    return "LI";
                case Country.Algeria:
                    return "DZ";
                case Country.Mongolia:
                    return "MN";
                case Country.Lebanon:
                    return "LB";
                case Country.Bahrain:
                    return "BH";
                case Country.Barbados:
                    return "BB";
                case Country.Azerbaijan:
                    return "AZ";
                case Country.Kuwait:
                    return "KW";
                case Country.Iraq:
                    return "IQ";
                case Country.Montenegro:
                    return "ME";
                case Country.Angola:
                    return "AO";
                case Country.Bangladesh:
                    return "BD";
                case Country.Yemen:
                    return "YE";
                case Country.Oman:
                    return "OM";
                case Country.Mozambique:
                    return "MZ";
                case Country.Ghana:
                    return "GH";
                case Country.Cambodia:
                    return "KH";
                case Country.Benin:
                    return "BJ";
                case Country.Qatar:
                    return "QA";
                case Country.Uganda:
                    return "UG";
                case Country.Maldives:
                    return "MV";
                case Country.Uzbekistan:
                    return "UZ";
                case Country.Cameroon:
                    return "CM";
                case Country.England:
                    return "England";
                case Country.USA:
                    return "US";
                case Country.Oceania:
                    return "AU";
                case Country.Scotland:
                    return "Scotland";
                case Country.Venezuela:
                    return "VE";
                case Country.SouthAfrica:
                    return "ZA";
                case Country.SouthKorea:
                    return "KR";
                case Country.Russia:
                    return "RU";
                case Country.CzechRepublic:
                    return "CZ";
                case Country.ChineseTaipei:
                    return "TW";
                case Country.HongKong:
                    return "HK";
                case Country.Wales:
                    return "Wales";
                case Country.BosniaHerzegovina:
                    return "BA";
                case Country.Vietnam:
                    return "VN";
                case Country.Bolivia:
                    return "BO";
                case Country.FaroeIslands:
                    return "FO";
                case Country.SaudiArabia:
                    return "SA";
                case Country.CostaRica:
                    return "CR";
                case Country.UnitedArabEmirates:
                    return "AE";
                case Country.Iran:
                    return "IR";
                case Country.DominicanRepublic:
                    return "DO";
                case Country.NorthernIreland:
                    return "GB";
                case Country.FYRMacedonia:
                    return "MK";
                case Country.ElSalvador:
                    return "SV";
                case Country.Moldova:
                    return "MD";
                case Country.TrinidadTobago:
                    return "TT";
                case Country.CapeVerde:
                    return "CV";
                case Country.IvoryCoast:
                    return "CI";
                case Country.Brunei:
                    return "BN";
                case Country.Syria:
                    return "SY";
                case Country.Tanzania:
                    return "TZ";
                case Country.Palestine:
                    return "PS";

                default:
                    return null;
            }
        }
     

        public static bool HasIsoCodeListed(string iso3166CountryCode)
        {
            return ISO3166_TO_COUNTRY_MAP.ContainsKey(iso3166CountryCode.ToUpper());
        }

        // updated when a new flag is added for a country
        public static Country Iso3166AsCountry(string iso3166CountryCode)
        {
            Country result;
            if (!ISO3166_TO_COUNTRY_MAP.TryGetValue(iso3166CountryCode.ToUpper(), out result))
                throw new System.ArgumentException("Not lisetd", "iso3166CountryCode");

            return result;
        }
    }
}



